package test.crane;

import ptolemy.actor.*;
import ptolemy.kernel.*;
import ptolemy.kernel.util.*;
import ptolemy.data.*;
import ptolemy.data.type.*;



//////////////////////////////////////////////////////////////////////////
//// Merger
/**

@author Ivan Jeukens
@version v 0.1 07/02/2002
*/
public class Merger extends TypedAtomicActor {

    public Merger(CompositeEntity container, String name) throws
            IllegalActionException, NameDuplicationException {
        super(container, name);

        input = new TypedIOPort(this, "input", true, false);
        input.setMultiport(true);

        output = new TypedIOPort(this, "output", false, true);
    }

    public TypedIOPort input;

    public TypedIOPort output;

    ///////////////////////////////////////////////////////////////////
    ////                         public methods                    ////

    public void fire() throws IllegalActionException {

        if(input.isKnown()) {
            for(int i = 0;i < input.getWidth();i++) {
                if(input.hasToken(i)) {
                    output.broadcast(input.get(i));
                }
            }
        }

        if(input.isKnown() && !output.isKnown()) {
            output.broadcastClear();
        }
    }

    ///////////////////////////////////////////////////////////////////
    ////                        private methods                    ////

    ///////////////////////////////////////////////////////////////////
    ////                      private variables                    ////

}
